package com.sghd.fight.module.game.config;

import com.sghd.common.ramcache.IEntity;
import com.sghd.common.ramcache.PerPersist;
import com.sghd.common.ramcache.anno.Cached;
import com.sghd.common.ramcache.anno.CachedSizes;
import com.sghd.common.ramcache.anno.Persister;
import com.sghd.common.ramcache.anno.Persisters;
import com.sghd.common.utils.json.JsonUtils;
import com.sghd.fight.module.game.core.Magic;
import com.sghd.pojo.fight.game.ChessType;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Entity
@Table(catalog = "bsdld_fight")
@Cached(size = CachedSizes.DEFAULT, persister = @Persister(Persisters.PRE_HALF_HOUR))
public class LevelConfig implements IEntity<LevelId> ,PerPersist {
    @EmbeddedId
    private LevelId id;
    /** 怪物ID*/
    private Integer monsterId;
    /** 普通行动*/
    private Integer common;
    /** 特殊行动*/
    @Column(name = "_unique")
    private Integer unique;
    /** 随机种子*/
    @Transient
    private List<Long> randoms;
    @Lob
    private String randomsJson;


    /** 怪物血量*/
    private int hp;
    /** 怪物血量上限*/
    private int hpMax;
    /** 玩家血量*/
    private int playerHp;
    /** 血量上限*/
    private int playerHpMax;
    /** 技能配置*/
    @Transient
    private Map<Integer,Integer> monsterSkills;
    @Lob
    private String monsterSkillsJson;
    @Transient
    private Map<ChessType,Integer> magics;
    @Lob
    private String magicsJson;
    @Transient
    private List<Integer> playerSkills;
    @Lob
    private String playerSkillsJson;
    /** 普通攻击ID*/
    private Integer attackId;
    /** 秒杀技能ID*/
    private Integer seckillId;

    @Override
    public LevelId getId() {
        return id;
    }

    public void setId(LevelId id) {
        this.id = id;
    }

    public Map<Integer,Integer> getMonsterSkills() {
        return monsterSkills;
    }

    public void setMonsterSkills(Map<Integer,Integer> monsterSkills) {
        this.monsterSkills = monsterSkills;
    }

    public String getMonsterSkillsJson() {
        return monsterSkillsJson;
    }

    public void setMonsterSkillsJson(String monsterSkillsJson) {
        this.monsterSkillsJson = monsterSkillsJson;
    }

    public List<Integer> getPlayerSkills() {
        return playerSkills;
    }

    public void setPlayerSkills(List<Integer> playerSkills) {
        this.playerSkills = playerSkills;
    }

    public String getPlayerSkillsJson() {
        return playerSkillsJson;
    }

    public void setPlayerSkillsJson(String playerSkillsJson) {
        this.playerSkillsJson = playerSkillsJson;
    }

    public Integer getMonsterId() {
        return monsterId;
    }

    public void setMonsterId(int monsterId) {
        this.monsterId = monsterId;
    }

    public Integer getCommon() {
        return common;
    }

    public void setCommon(int common) {
        this.common = common;
    }

    public Integer getUnique() {
        return unique;
    }

    public void setUnique(int unique) {
        this.unique = unique;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getPlayerHp() {
        return playerHp;
    }

    public void setPlayerHp(int playerHp) {
        this.playerHp = playerHp;
    }

    public Integer getAttackId() {
        return attackId;
    }

    public void setAttackId(Integer attackId) {
        this.attackId = attackId;
    }

    public Integer getSeckillId() {
        return seckillId;
    }

    public void setSeckillId(Integer seckillId) {
        this.seckillId = seckillId;
    }

    public int getPlayerHpMax() {
        return playerHpMax;
    }

    public void setPlayerHpMax(int playerHpMax) {
        this.playerHpMax = playerHpMax;
    }

    public Map<ChessType, Integer> getMagics() {
        return magics;
    }

    public void setMagics(Map<ChessType, Integer> magics) {
        this.magics = magics;
    }

    public String getMagicsJson() {
        return magicsJson;
    }

    public void setMagicsJson(String magicsJson) {
        this.magicsJson = magicsJson;
    }

    public int getHpMax() {
        return hpMax;
    }

    public void setHpMax(int hpMax) {
        this.hpMax = hpMax;
    }

    public List<Long> getRandoms() {
        return randoms;
    }

    public void setRandoms(List<Long> randoms) {
        this.randoms = randoms;
    }

    public String getRandomsJson() {
        return randomsJson;
    }

    public void setRandomsJson(String randomsJson) {
        this.randomsJson = randomsJson;
    }

    @Override
    public void afterLoad() {
        monsterSkills = JsonUtils.string2Map(monsterSkillsJson,  Integer.class,Integer.class,HashMap.class);
        magics = JsonUtils.string2Map(magicsJson,  ChessType.class,Integer.class,HashMap.class);
        playerSkills = JsonUtils.string2Collection(playerSkillsJson, ArrayList.class, Integer.class);
        randoms = JsonUtils.string2Collection(randomsJson, ArrayList.class, Long.class);
    }
    @Override
    public void beforePersist() {
        monsterSkillsJson = JsonUtils.object2String(monsterSkills);
        magicsJson = JsonUtils.object2String(magics);
        playerSkillsJson = JsonUtils.object2String(playerSkills);
        randomsJson = JsonUtils.object2String(randoms);
    }
    public LevelConfig copy(){
        LevelConfig levelConfig = new LevelConfig();
        levelConfig.common = common;
        levelConfig.id = id;
        levelConfig.monsterId = monsterId;
        levelConfig.unique = unique;
        levelConfig.randoms = randoms;
        levelConfig.playerSkills = playerSkills;
        levelConfig.monsterSkills = monsterSkills;
        levelConfig.hp = hp;
        levelConfig.hpMax = hpMax;
        levelConfig.playerHp = playerHp;
        levelConfig.playerHpMax = playerHpMax;
        levelConfig.attackId = attackId;
        levelConfig.seckillId = seckillId;
        levelConfig.magics = magics;
        return levelConfig;
    }
}
